﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%: ViewBag.Message %></h2>
 
   <%: Html.Kendo().Grid<VnResource.DataContract.Models.ProductViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ProductName).Width(200);
            columns.Bound(p => p.UnitPrice).Width(100);
            columns.Bound(p => p.UnitsInStock).Width(100);
            columns.Bound(p => p.Discontinued).Width(100);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
            //columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
        })
        .ToolBar(toolbar => toolbar.Custom().Text("Tạo mới").HtmlAttributes(new { id = "customCommand" , IsPostBack= false }))
        //.Editable(editable => editable.Mode(GridEditMode.PopUp))
        .Pageable()
        .Sortable()
        .Scrollable()
        .HtmlAttributes(new { style = "height:430px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Events(events => events.Error("error_handler"))
            .Model(model => model.Id(p => p.ProductID))
                   .Create(update => update.Action("EditingPopup_Create", "Home"))
                   .Read(read => read.Action("EditingPopup_Read", "Home"))
                   .Update(update => update.Action("EditingPopup_Update", "Home"))
                   .Destroy(update => update.Action("EditingPopup_Destroy", "Home"))
        )
    %>

    <%
    Html.Kendo().Window()
        .Name("window")
        .Visible(false)
        .Animation(animation =>
        {
            animation.Open(open =>
            {
                open.Zoom(ZoomDirection.In);
            });
            
            animation.Close(close =>
            {
                close.Reverse(true);
                close.Zoom(ZoomDirection.Out);
                close.Reverse(false);                  
                                 
            });
        })
        .Content(() => 
        {
            Html.RenderPartial("Hinh");
            %>

            <%--<div style="text-align: center;">
                    <img src="<%=Url.Content("~/Content/web/window/egg-chair.png")%>" alt="ARNE JACOBSEN EGG CHAIR" />
                    <p>ARNE JACOBSEN EGG CHAIR<br /> Image by: <a href="http://www.conranshop.co.uk/" title="http://www.conranshop.co.uk/">http://www.conranshop.co.uk/</a></p>
                </div>    --%>    
            <%
        })
        .Width(600)
        
        .Draggable()
        .Resizable()
        .Title("Ngày nghỉ")
        .Events(events=> events.Close("close"))
        .Render();
%>
    <script type="text/javascript">
        function error_handler(e) {
            if (e.errors) {
                var message = "Errors:\n";
                $.each(e.errors, function (key, value) {
                    if ('errors' in value) {
                        $.each(value.errors, function () {
                            message += this + "\n";
                        });
                    }
                });
                alert(message);
            }
        }
        $("#customCommand").click(function (e) {
            e.preventDefault();
            $("#window").data("kendoWindow").open();
            $("#window").data("kendoWindow").center();
            $("#undo").fadeOut(300);
            //put custom logic here
        });
        function close() {
            $("#undo").fadeIn(300);
        }

        $("#undo")
        .bind("click", function () {
            $("#window").data("kendoWindow").open();
            $("#undo").fadeOut(300);
        });

    </script>


</asp:Content>
